.macro WriteFile(name, startAddr, endAddr)
{
    lda #[filename_end-filename]
    ldx #<filename
    ldy #>filename
    jsr $ffbd // SETNAM

    lda #1 // logical file number
    ldx #8 // device no.
    ldy #0 // secondary address
    jsr $ffba // SETLFS

    lda #<startAddr
    sta 251
    lda #>startAddr
    sta 252
    lda #251
    ldx #<endAddr
    ldy #>endAddr        
    jsr $ffd8 // SAVE
    jmp done
filename:
    .text name
filename_end:
done:
}
